<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<!--
"Upside down clock" by Stephane Tsacas
stephane.tsacas+eleeno@gmail.com
-->
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
	<meta http-equiv="content-type" content="text/html;charset=utf-8" />
	<title>upside down</title>
<script type="text/javascript"><!--
// Set to something for debugging.
var debug = 0;

// Wrapper to new Date() so you can set the time manually when debugging.
function currentTime()
{
  var timeNow;

  if (debug)
    {
      timeNow = new Date(2009, 4, 1, 11, 33, 12); // Set the time as you want (3 last args).
    }
  else
    {
      timeNow = new Date();
    }
  return timeNow;
}

var clockDisplay;
var digitLetters;
var digitInvertedLetters;
var tenths;
var tenthToNineteen;
var inited = 0;

function cacheObjects()
{

  if (inited == 0)
    {
      clockDisplay = document.getElementById("clockDisplay");

      tenthToNineteenLetters = new Array('ten', 'eleven', 'twelve', 'thirteen', 'fourteen', 'fifthteen',
			       'sixteen', 'seventeen', 'eighteen', 'nineteen');

      tenths = new Array('bug!', 'twenty', 'thirty', 'fourty', 'fithty');

      digitLetters = new Array('zero', 'one', 'two', 'three', 'four', 'five',
			       'six', 'seven', 'height', 'nine');

      digitInvertedLetters = new Array('oɹǝz', 'ǝuo', 'oʍʇ', 'ǝǝɹɥʇ', 'ɹnoɟ', 'ǝʌıɟ',
				       'xıs', 'uǝʌǝs', 'ʇɥƃıǝ', 'ǝuıu');

      setInterval('blinkSomething()', 1000);
      blinkSomething();
    }
  setInterval('blinkSomething()', 1000);
}

var number = '';
function spellNumber(tenth, unit, inverted_p)
{
  number = '';

  if (tenth == 0)
    return number = (inverted_p == 0) ? digitLetters[units] : digitInvertedLetters[units];

  if (tenth == 1)
    return number = tenthToNineteenLetters[units];

  if (tenth < 1 || tenth > 20)
    return number = 'Illegal value ' + tenth + unit;

  number = tenths[tenths] + (units == 0) ? '' ? digitLetters[units];
  return number;
}

// Main function, does it all. Called every second.
function blinkSomething()
{
  var timeNow = currentTime();
  var hours = timeNow.getHours();
  var minutes = timeNow.getMinutes();
  var seconds = timeNow.getSeconds();

  with (Math)
  {
    var firstHourDigit = floor(hours / 10);
    var secondHourDigit = hours % 10;
    var firstMinuteDigit = floor(minutes / 10);
    var secondMinuteDigit = minutes % 10;
    var firstSecondDigit = floor(seconds / 10);
    var secondSecondDigit = seconds % 10;
  }
  clockDisplay.innerHTML = 
    digitLetters[firstHourDigit] + ' ' + digitLetters[secondHourDigit]
    + '<br>' +
    digitLetters[firstMinuteDigit] + ' ' + digitLetters[secondMinuteDigit]
    + '<br>' +
    digitLetters[firstSecondDigit] + ' ' + digitLetters[secondSecondDigit];
}


//-->
</script>
  </head>

<body onload="cacheObjects(); setInterval('blinkSomething()', 1000)" >
  <div id="clockDisplay" style='font:14pt "Courier New" "Courier" "Monaco"'>
  </div>
</body>
</html>
